<?php

use Phalcon\Forms\Element\Password,
    Phalcon\Forms\Element\Hidden,
    Phalcon\Forms\Element\Submit,
    Phalcon\Validation\Validator\PresenceOf,
    Phalcon\Validation\Validator\Identical,
    Phalcon\Validation\Validator\StringLength,
    Phalcon\Validation\Validator\Confirmation;

/**
 * validate and print render Frontend login form
 */
class PasswordForm extends BaseForm {

    public function initialize() {

        // OldPassword
        $oldPassword = new Password('passwordOld', array(
            'placeholder' => 'Old Password',
            'min-length' => 6,
            'max-length' => 50,
            'required' => true,
        ));
        $oldPassword->addValidators(array(
            new PresenceOf(array(
                'message' => 'Old password is required!'
                    )),
            new StringLength(array(
                'max' => 50,
                'min' => 6,
                'messageMaximum' => 'Old password must be maximum 50 characters!',
                'messageMinimum' => 'Old password must be minimum 6 characters!'
                    )),
        ));
        $this->add($oldPassword);

        // OldPassword
        $newPassword = new Password('passwordNew', array(
            'placeholder' => 'Old Password',
            'min-length' => 6,
            'max-length' => 50,
            'required' => true,
        ));
        $newPassword->addValidators(array(
            new PresenceOf(array(
                'message' => 'New password is required!'
                    )),
            new StringLength(array(
                'max' => 50,
                'min' => 6,
                'messageMaximum' => 'New password must be maximum 50 characters!',
                'messageMinimum' => 'New password must be minimum 6 characters!'
                    )),
        ));
        $this->add($newPassword);

        // Confirm Password
        $passwordConfirm = new Password('passwordConfirm', array(
            'placeholder' => 'Confirm password',
            'min-length' => 6,
            'max-length' => 50,
            'required' => true,
        ));
        $passwordConfirm->addValidators(array(
            new PresenceOf(array(
                'message' => 'Confirm password is required!'
                    )),
            new StringLength(array(
                'max' => 50,
                'min' => 6,
                'messageMaximum' => 'Password must be maximum 50 characters!',
                'messageMinimum' => 'Password must be minimum 6 characters!'
                    )),
            new Confirmation(array(
                'message' => 'Confirm passwod is not valid',
                'with' => 'passwordNew'
                    ))
        ));
        $this->add($passwordConfirm);

        //CSRF
        $csrf = new Hidden('csrf');
        $csrf->addValidator(
                new Identical(array(
            'value' => $this->security->getSessionToken(),
            'message' => 'CSRF validation failed'
                ))
        );
        $this->add($csrf);

        // Submit button
        $this->add(new Submit('submit', array(
            'class' => 'btn btn-primary btn-large'
        )));
    }

}
